const express = require("express")
const router = express.Router()
const activityDB = require("../../db/activity")

// 数据块数据
router.get("/block", async (req, res) => {
  try {
    const visitorList = await activityDB.find()

    // 活动场次
    const activities = visitorList.length
    // 活动人数
    const peoples = visitorList.reduce(
      (prev, next) => prev + next.participant,
      0
    )
    // 帮助人数
    const helps = (1000 + Math.random() * 1000) | 0
    // 活动地点
    const places = 189
    res.send({
      code: 0,
      mes: "数据块内容",
      data: {
        activities,
        peoples,
        helps,
        places,
      },
    })
  } catch (error) {
    res.send({
      code: 5,
      mes: "服务器异常,请稍后再试",
    })
  }
})

module.exports = router
